package com.filter.component;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

/**
 * @Description 过滤器1
 *
 * @author 堆堆堆
 * @date 2018年4月17日 下午4:47:05
 */
@WebFilter(filterName = "filter1", urlPatterns = "/*")
public class Filter1 implements Filter {

	/**
	 * 过滤器销毁
	 */
	@Override
	public void destroy() {
		System.out.println("过滤器1销毁");
	}

	/**
	 * 执行过滤操作
	 */
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		System.out.println("执行过滤1操作");

		// 将请求转发给过滤器链中下一个 filter，若无 filter，则转发到请求的资源
		chain.doFilter(request, response);
	}

	/**
	 * 过滤器初始化
	 */
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		System.out.println("过滤器1初始化");
	}

}
